package com.yycx.module.bus.provider.handler.haiying.common;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.client.entity.BusSaleman;
import com.yycx.module.system.client.entity.SysCompany;
import com.yycx.module.system.client.entity.SysOrganization;
import com.yycx.module.user.client.entity.AppPosition;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 业务员选择
 *
 * @author zyf
 */
@Component
public class SaleManPageListHandler implements PageInterceptor<BusSaleman> {


    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        cq.select(BusSaleman.class, "*");
        cq.addSelect(SysOrganization.class, "organizationName");
        cq.addSelect(SysCompany.class, "companyName");
        cq.addSelect(BusDept.class, "deptName", "deptType");
        cq.addSelect(AppPosition.class, "positionName");
        cq.like(BusSaleman.class, "saleManName");
        cq.eq(BusSaleman.class, "organizationId");
        cq.eq(BusDept.class, "deptType");
        cq.eq(BusSaleman.class, "deptId");
        cq.like(BusSaleman.class, "linkTel");
        cq.eq(true, "saleman.saleManType", 1);
        cq.like(BusSaleman.class, "saleManBusinessNo");
        cq.createJoin(SysCompany.class);
        cq.createJoin(SysOrganization.class);
        cq.createJoin(BusDept.class);
        cq.createJoin(AppPosition.class);
        cq.orderByAsc("saleman.saleManCode");
    }

}
